package com.zkingsoft.actions.admin;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.model.PaginationVO;
import com.zkingsoft.model.ShowBox;
import com.zkingsoft.model.ShowPoint;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.ShowBoxService;
import com.zkingsoft.services.ShowPointService;

/**
 * @project MatrixCms
 * @package com.zkingsoft.actions.admin
 * @class ShowPointController.java
 * @author Matrix-J E-mail:<935090232@qq.com>
 * @date 2016年4月21日10:31
 * @description 展位管理
 */
@Controller
@RequestMapping(value = "/admin/showPoint")
public class ShowPointController extends BaseController {


	@Resource
	private ShowPointService currentService;

	@Resource
	private ShowBoxService showBoxService;

	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(HttpServletRequest request, ShowPoint showPoint, PaginationVO pageVo) {
		showPoint.setCompanyId(getMe().getCompanyId());
		return showList(currentService, showPoint, pageVo);
	}

	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(ShowPoint showPoint,HttpServletRequest request) {
		if (showPoint.getId() != null) {
			return modify(currentService, showPoint, "广告位");
		} else {
			showPoint.setCompanyId(getMe(request).getCompanyId());
			showPoint.setCreateTime(new Date());
			return add(currentService, showPoint, "广告位");
		}
	}

	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}

	@RequestMapping(value = "/editForm")
	public String editForm(Long id, HttpServletRequest request) {
		ShowPoint showPoint;
		ShowBox showBox = new ShowBox();
		showBox.setCompanyId(getMe().getCompanyId());
		List<ShowBox> list = showBoxService.findByModel(showBox);
		if (id != null) {
			showPoint = currentService.findById(id);
			request.setAttribute("obj", showPoint);
		}
		request.setAttribute("list", list);
		return "admin/showPoint-form";
	}

	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all(HttpServletRequest request) {
		ShowPoint showPoint = new ShowPoint();
		showPoint.setCompanyId(getMe(request).getCompanyId());
		return findByModel(currentService, null);
	}
}